import {
  List,
  borrowList,
  bidInfo,
  bidAfter,
} from '../api/bid';
import { message } from 'antd/lib/index';
import checkStatus from '@/utils/status';

export default {
  namespace: 'bid',

  state: {
    data: {
      data: [],
      pagination: {},
    },
  },
  effects: {
    //请求列表
    * fetch({ payload }, { call, put }) {
      const response = yield call(List, payload);
      yield checkStatus(response);
      yield put({
        type: 'get',
        payload: response.msg,
      });
    },
    //增加
    * borrowList({ payload, callback }, { call, put }) {
      const response = yield call(borrowList, payload);
      yield checkStatus(response);
      yield put({
        type: 'setBorrowList',
        payload: response,
      });
    },

    * bidInfo({ payload, callback }, { call, put }) {
      const response = yield call(bidInfo, payload);
      yield checkStatus(response);
      yield put({
        type: 'setBidInfo',
        payload: response,
      });
    },

    * bidAfter({ payload, callback }, { call, put }) {
      const response = yield call(bidAfter, payload);
      yield checkStatus(response);
      yield put({
        type: 'setAfter',
        payload: response,
      });
    },


  },

  reducers: {
    get(state, action) {
      state.pagination = {
        pageSize: action.payload.pageSize,
        current: action.payload.pageNo,
        total: action.payload.total,
      };
      return {
        ...state,
        data: action.payload,
      };
    },
    setBorrowList(state, action) {
      return {
        ...state,
        borrowList: action.payload,
      };
    },
    setBidInfo(state, action) {
      return {
        ...state,
        bidInfo: action.payload,
      };
    },
    setAfter(state, action) {
      return {
        ...state,
        afterInfo: action.payload,
      };
    },

    getdesc(state, action) {
      return {
        ...state,
        Desc: action.payload,
      };
    },


  },
};
